/*
 * @Author: yjp
 * @Date: 2022-03-17 17:01:15
 */
import { request } from 'umi';
import { UserEntity } from './entities';
import { CREATE, DELETE, UPDATE, LIST } from '@/constant';

const route = '/user';

export async function getUser(id: string) {
  return await request<UserEntity>(`${route}/get_entity?id=${id}`, {
    method: 'GET',
  });
}

export async function listUser(params: {
  current?: number;
  pageSize?: number;
}) {
  return request<{
    data: UserEntity[];
    total?: number;
    success?: boolean
  }>(`${route}${LIST}`, {
    method: 'GET',
    params,
  });
}

export async function addUser(data: { [key: string]: any }) {
  return request<Record<string, any>>(`${route}${CREATE}`, {
    data,
    method: 'POST',
  });
}

export async function updateUser(data: { [key: string]: any }) {
  return request<Record<string, any>>(`${route}${UPDATE}`, {
    data,
    method: 'POST',
  });
}

export async function deleteUser(data: string) {
  return request<Record<string, any>>(`${route}${DELETE}?ids=${data}`, {
    method: 'GET',
  });
}

export async function updateRoles(data: { [key: string]: any }) {
  return request<Record<string, any>>(`${route}/edit_user_group`, {
    data,
    method: 'POST',
  });
}

export async function updatePassword(data: { [key: string]: any }) {
  return request<Record<string, any>>(`${route}/change_password`, {
    data,
    method: 'POST',
  });
}
